import axios from 'axios'
import { beforeRequest, requestError, afterResponse, responseError } from './request-options'

const baseURL = 'http://localhost:3000/'

const request = axios.create({ baseURL, timeout: 30000 })

// 请求拦截器
request.interceptors.request.use(
  beforeRequest,
  (error) => requestError(error, false)
)

// 响应拦截器
request.interceptors.response.use(
  (response) => afterResponse(response, false),
  (error) => responseError(error, false)
)

export {
  request
}
